package me.hunche.app.job;

import java.util.Date;
import java.util.List;

import me.hunche.app.domain.Activity;
import me.hunche.app.service.ActivityService;
import me.hunche.app.service.CoreService;
import me.hunche.app.service.NotifyService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hp.hpl.helper.misc.DateHelper;

//@Service
public class ReadyJob {
	
	private static final Logger logger = Logger.getLogger(ReadyJob.class);

	@Autowired private NotifyService ns;
//	@Autowired private ActivityDao ad;
	@Autowired private ActivityService activityService;
	
	@Autowired private CoreService coreService;
	
	public void run(){
		if(logger.isDebugEnabled()){
			logger.debug("ReadyJob start");
		}
		
		Date tomorrow = DateHelper.dayStart(DateHelper.now(), 1);//1
//		Date d = new Date(ds.getTime());
		List<Activity> as = activityService.findByActivityDateAndStatus(tomorrow,Activity.STATUS_PREP);
		if(as!=null && !as.isEmpty()){
			for(Activity a:as){
//				ns.ready(a);
				coreService.ready(a);
			}
		}
		
		if(logger.isInfoEnabled()){
			logger.info("ReadyJob "+as.size()+" end");
		}
	}
}
